package group.sicher.lock.brain;

import group.sicher.lock.annotation.MarsLock;
import group.sicher.lock.brain.lock.MarsKeyLockAbstractor;

/**
 * @description:
 * @author: aron
 * @date: 2019-08-05 17:16
 */
public class MarsKeyLockContext {

    private MarsKeyLockAbstractor marsKeyLockAbstractor;

    public MarsKeyLockContext(MarsKeyLockAbstractor marsKeyLockAbstractor) {
        this.marsKeyLockAbstractor = marsKeyLockAbstractor;
    }

    public MarsLockKey instance(MarsLock lock) {
        return this.marsKeyLockAbstractor.builder().setLeaseTime(lock.lockTime())
                .setTimeUnit(lock.timeUnit())
                .setWaitTime(lock.waitTime())
                .build();
    }
}
